# ================================================================================
# Copyright (c) 2008, Earlybird Technology Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Earlybird Technology Inc. nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY Earlybird Technology Inc. ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Earlybird Technology Inc. BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ================================================================================

# Google API's and Extensions
from google.appengine.ext import webapp
from google.appengine.ext import db

# Datastore Model
class Project(db.Model):
    display_name = db.StringProperty()
    summary = db.TextProperty()
    
class CreateProject(webapp.RequestHandler):
    # This form will gather the information nessessary to create a new punch entity.
    def get(self):
        self.response.headers['Content-Type']= 'text/html'
        self.response.out.write("""
          <html>
            <body>
                <form action="/create_project" method="post">
                Display Name: <br /><input type="text" name="display_name" maxlength="500" /><br /><br />
                Additional Information: <br/><textarea name="additional_information" rows="4" cols="40"></textarea><br /><br /></div>
                <input type="submit" value="Create" />
                </form>
            </body>
          </html>""")
          
    # This Post method can be used to create a new project by anything (browsers or clients)
    # seperate function should be used to record the data in the datastore module.
    # i.e. http://mydomain.com/punch?project=Punchcard&hours=4.5&summary=Added+web+interface.
    def post(self):
        # prepending 'key_' to key_name sanitizes it. 
        # The key should never change after cration. The display name can change independantly.
        new_project = Project()
        new_project.display_name = self.request.get('display_name')
        new_project.summary = self.request.get('additional_information')
        new_project.put()
                
        self.redirect("/")
